package cn.jichangxiu.ucenter.mapper;

import cn.jichangxiu.common.ucenter.entity.Authority;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AuthorityMapper extends JpaRepository<Authority, String>, JpaSpecificationExecutor<Authority> {

    @Query(nativeQuery = true , value = "SELECT * FROM prey_authority a , prey_role_auth b WHERE a.id = b.auth_id AND b.role_id = ?")
    List<Authority> findAuthoritiesByRoleId(String roleId);

    @Query(nativeQuery = true , value = "SELECT * FROM prey_authority a , prey_role_auth b WHERE a.id = b.auth_id AND b.role_id in (:roleIds)")
    List<Authority> findAuthoritiesByRoleIdMany(@Param("roleIds") List<String> roleIds);

    @Query(nativeQuery = true , value = "SELECT * FROM prey_authority a WHERE a.id in (:authIds)")
    List<Authority> findAuthoritiesByAuthIds(@Param("authIds") List<String> authIds);
}
